import requests
from api.ihrm_login import IhrmLoginApi


class IhrmEmpApi():

    @classmethod
    def add_emp(cls, header, json):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/user", headers=header, json=json)
        return resp

    @classmethod
    def query_emp(cls, emp_id, header):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id, headers=header)
        return resp

    @classmethod
    def modify_emp(cls, emp_id, header, json):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id, headers=header, json=json)
        return resp

    @classmethod
    def delete_emp(cls, emp_id, header):
        resp = requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id, headers=header)
        return resp


if __name__ == '__main__':
    data = {"mobile": "13800000002", "password": "123456"}
    token = IhrmLoginApi.ihrm_login(data).json().get("data")
    header = {"Authorization": f"{token}"}
    json1 = {"username": "小鱼a",
             "mobile": "13831743338",
             "workNumber": "272215"}
    json2 = {"username": "吴天啊"}
    emp_id = "1495308553991348224"
    resp = IhrmEmpApi.add_emp(header, json1)
    # resp = IhrmEmpApi.query_emp(emp_id,header)
    # resp = IhrmEmpApi.modify_emp(emp_id,header,json2)
    # resp = IhrmEmpApi.delete_emp(emp_id, header)
    print(resp.json())
